home *** CD-ROM | disk | FTP | other *** search
- Path: news.capitalnet.com!usenet
- From: wingl@capitalnet.com
- Newsgroups: comp.lang.c++
- Subject: Help: How to initialize objects created by new class[x]
- Date: 5 Jan 1996 05:19:34 GMT
- Organization: Capitalnet
- Message-ID: <4cicd6$lsv@news.capitalnet.com>
- Reply-To: wingl@bnr.ca
- NNTP-Posting-Host: user77.capitalnet.com
- Keywords: new array
- X-Newsreader: IBM NewsReader/2 v1.2
-
- Let say I have the following class
-
- My_class {
- public:
- int (int i=0) : a(i), b(i) {}
- private:
- int a, b;
- }
-
- For the following statement, default constructor is involved upon
- the creation of the object.
-
- My_class* my_ptr= new My_class;
-
- However, if I use
- My_class* my_ptr= new My_class[10];
-
- to allocate 10 objects of class My_class, then C++ would not
- call any constructor to do any initialization. All the objects
- allocated are not initializated at all.
-
- I wonder what is the proper way to perform object initialization
- whenever an array of objects are created? As long as a constructor
- is involved for each of the object in the array, I don't care if all the
- objects are initializated the same or not.
-
- If there is no way to get constructor to initialize an array of objects
- upon creation. Does that means one should not do so?
-
- Thanks for any help.
-
- Wing
- wingl@bnr.ca
-